/**
 * HTTP 相关常量
 */

/**
 * HTTP 请求方法
 */
export const HTTP_METHOD = {
  GET: 'GET',
  POST: 'POST',
  PUT: 'PUT',
  DELETE: 'DELETE',
  PATCH: 'PATCH',
} as const;

/**
 * HTTP 请求方法类型
 */
export type HttpMethod = typeof HTTP_METHOD[keyof typeof HTTP_METHOD];

/**
 * HTTP 请求方法选项（用于下拉框）
 */
export const HTTP_METHOD_OPTIONS = [
  { label: 'GET', value: HTTP_METHOD.GET },
  { label: 'POST', value: HTTP_METHOD.POST },
  { label: 'PUT', value: HTTP_METHOD.PUT },
  { label: 'DELETE', value: HTTP_METHOD.DELETE },
  { label: 'PATCH', value: HTTP_METHOD.PATCH },
] as const;

/**
 * HTTP 状态码范围
 */
export const HTTP_STATUS_RANGE = {
  /** 成功范围 2xx */
  SUCCESS_MIN: 200,
  SUCCESS_MAX: 299,
  /** 客户端错误范围 4xx */
  CLIENT_ERROR_MIN: 400,
  CLIENT_ERROR_MAX: 499,
  /** 服务器错误范围 5xx */
  SERVER_ERROR_MIN: 500,
  SERVER_ERROR_MAX: 599,
} as const;

/**
 * 根据 HTTP 状态码获取颜色
 * @param statusCode HTTP 状态码
 * @returns Ant Design Tag 颜色
 */
export const getHttpStatusColor = (statusCode: number | null): string => {
  if (!statusCode) return 'default';
  if (statusCode >= HTTP_STATUS_RANGE.SUCCESS_MIN && statusCode <= HTTP_STATUS_RANGE.SUCCESS_MAX) {
    return 'success';
  }
  if (statusCode >= HTTP_STATUS_RANGE.CLIENT_ERROR_MIN) {
    return 'error';
  }
  return 'default';
};

